/**********************************************************************************************************
** 驱动文件：	jmkt-SAF13WTR00.c
** 驱动类型：	jmkt
** 设备名称：	精密空调
** 设备型号：	SAF13WTR00
** 设备品牌：	美的
** 设备协议：	电总协议
** 驱动描述：	美的精密空调监测
** 生成日期：	2018-04-02 10:03:07
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var indoorTemp;								//室内温度
	Var outdoorTemp;							//室外温度
	Var setTempUpper;							//设置温度上限
	Var setTempLower;							//设置温度下限
	Var setCoolingTemp;							//制冷温度设定值
	Var setHeatingTemp;							//制热温度设定值
	Var autoMode;								//自动模式
	Var energyMode;								//节能模式
	Var freshAirMode;							//新风模式
	Var coldMode;								//制冷模式
	Var heatMode;								//制热模式
	Var dehumiMode;								//抽湿模式
	Var standbyMode;							//待机模式
	Var runningState;							//运行状态
	Var indoorWindVolume;						//室内风机风速
	Var freshAirDoor;							//新风门
	Var outdoorFan;								//室外风机
	Var indoorFan;								//室内风机
	Var compressor;								//压缩机
	Var heater;									//电加热
	Var alarmOutput;							//报警输出
	Var EEPROMFault;							//EEPROM参数
	Var T1aFault;								//T1a温度传感器
	Var T1bFault;								//T1b温度传感器
	Var T2Fault;								//T2温度传感器
	Var T3Fault;								//T3温度传感器
	Var T4Fault;								//T4温度传感器
	Var airFlowAlarm;							//空气流量
	Var lostPhase;								//电源缺相
	Var exhaustTempSensor;						//排气温度传感器
	Var humiSensor;								//湿度传感器
	Var voltageFault;							//电压异常
	Var photoelectricSwitch;					//光电开关
	Var leakingAlarm;							//漏水报警
	Var fireAlarm;								//烟火报警
	Var indoorHighTemp;							//室内高温
	Var indoorLowTemp;							//室内低温
	Var indoorEvaporatorProtection;				//室内蒸发器保护
	Var outdoorCondenserProtection;				//室外冷凝器保护
	Var exhausthighTempProtection;				//排气高温保护
	Var compressorLowPressure;					//压缩机低压故障
	Var compressorHighPressure;					//压缩机高压故障
	Var compressorOverload;						//压缩机电流过载
	Var heaterOverload;							//电加热过载
	Var filterBlock;							//新风过滤网脏堵
	Var indoorFanRunTime;						//内风机运行时间
	Var compressorRunTime;						//压缩机运行时间
	Var outdoorFanRunTime;						//外风机运行时间
	Var freshAirRunTime;						//换新风运行时间
	Var heaterRunTime;							//加热器运行时间
	Var powerConsumption;						//总耗电量
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		FLOAT,
		0,
		READONLY,
		"indoorTemp",
		"室内温度",
		"℃",
		"当前室内温度",
		0,
		0,
		"当前室内温度过高",
		"当前室内温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outdoorTemp",
		"室外温度",
		"℃",
		"当前室外温度",
		0,
		0,
		"当前室外温度过高",
		"当前室外温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setTempUpper",
		"设置温度上限",
		"℃",
		"设置温度上限",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setTempLower",
		"设置温度下限",
		"℃",
		"设置温度下限",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setCoolingTemp",
		"制冷温度设定值",
		"℃",
		"制冷温度设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setHeatingTemp",
		"制热温度设定值",
		"℃",
		"制热温度设定值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"autoMode",
		"自动模式",
		"",
		"自动模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"energyMode",
		"节能模式",
		"",
		"节能模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"freshAirMode",
		"新风模式",
		"",
		"新风模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"coldMode",
		"制冷模式",
		"",
		"制冷模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heatMode",
		"制热模式",
		"",
		"制热模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"dehumiMode",
		"抽湿模式",
		"",
		"抽湿模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"standbyMode",
		"待机模式",
		"",
		"待机模式，0：停止/1：启动",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"runningState",
		"运行状态",
		"",
		"运行状态，0：关机/1：开机",
		0,
		0,
		"关机",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"indoorWindVolume",
		"室内风机风速",
		"",
		"运行状态，0：低风/1：高风",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"freshAirDoor",
		"新风门",
		"",
		"新风门，0：关闭/1：打开",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"outdoorFan",
		"室外风机",
		"",
		"室外风机，0：关闭/1：运行",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"indoorFan",
		"室内风机",
		"",
		"室内风机，0：关闭/1：运行",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor",
		"压缩机",
		"",
		"压缩机，0：关闭/1：运行",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heater",
		"电加热",
		"",
		"压缩机，0：关闭/1：运行",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"alarmOutput",
		"报警输出",
		"",
		"报警输出，0：关闭/1：运行",
		0,
		0,
		"关闭",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EEPROMFault",
		"EEPROM参数",
		"",
		"EEPROM参数故障,0:正常/1:错误",
		0,
		0,
		"错误",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"T1aFault",
		"T1a温度传感器",
		"",
		"T1a温度传感器故障,0:正常/1:故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"T1bFault",
		"T1b温度传感器",
		"",
		"T1b温度传感器故障,0:正常/1:故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"T2Fault",
		"T2温度传感器",
		"",
		"T2温度传感器故障,0:正常/1:故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"T3Fault",
		"T3温度传感器",
		"",
		"T3温度传感器故障,0:正常/1:故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"T4Fault",
		"T4温度传感器",
		"",
		"T4温度传感器故障,0:正常/1:故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"airFlowAlarm",
		"空气流量",
		"",
		"空气流量故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"lostPhase",
		"电源缺相",
		"",
		"电源缺相故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"exhaustTempSensor",
		"排气温度传感器",
		"",
		"排气温度传感器故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humiSensor",
		"湿度传感器",
		"",
		"湿度传感器故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"voltageFault",
		"电压异常",
		"",
		"电压异常,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"photoelectricSwitch",
		"光电开关",
		"",
		"光电开关,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"leakingAlarm",
		"漏水报警",
		"",
		"漏水报警,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fireAlarm",
		"烟火报警",
		"",
		"烟火报警,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"indoorHighTemp",
		"室内高温",
		"",
		"室内高温报警,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"indoorLowTemp",
		"室内低温",
		"",
		"室内低温报警,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"indoorEvaporatorProtection",
		"室内蒸发器保护",
		"",
		"室内蒸发器高温或低温保护,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"outdoorCondenserProtection",
		"室外冷凝器保护",
		"",
		"室外冷凝器高温保护,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"exhausthighTempProtection",
		"排气高温保护",
		"",
		"排气高温保护,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressorLowPressure",
		"压缩机低压故障",
		"",
		"压缩机低压故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressorHighPressure",
		"压缩机高压故障",
		"",
		"压缩机高压故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressorOverload",
		"压缩机电流过载",
		"",
		"压缩机电流过载故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heaterOverload",
		"电加热过载",
		"",
		"电加热过载故障,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"filterBlock",
		"新风过滤网脏堵",
		"",
		"新风过滤网脏堵,0:正常/1:报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"indoorFanRunTime",
		"内风机运行时间",
		"小时",
		"内风机运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"compressorRunTime",
		"压缩机运行时间",
		"小时",
		"压缩机运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"outdoorFanRunTime",
		"外风机运行时间",
		"小时",
		"外风机运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"freshAirRunTime",
		"换新风运行时间",
		"小时",
		"换新风运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"heaterRunTime",
		"加热器运行时间",
		"小时",
		"加热器运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"powerConsumption",
		"总耗电量",
		"KW•h",
		"总耗电量",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:		//获取模拟量化后的数据 (定点数 )
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x34\x32\x30\x30\x30\x30\x46\x44\x42\x30\x0D");
			break;
		case 1:		//获取系统参数(定点数)
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x34\x37\x30\x30\x30\x30\x46\x44\x41\x42\x0D");
			break;		
		case 2:		//获取机组状态
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x38\x32\x30\x30\x30\x30\x46\x44\x41\x43\x0D");
			break;
		case 3:		//获取负载运行时间
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x38\x33\x30\x30\x30\x30\x46\x44\x41\x42\x0D");
			break;
		case 4:		//获取设备耗电量
			*len = sprintf(cmd,"\x7E\x32\x31\x30\x31\x36\x30\x38\x35\x45\x30\x30\x32\x30\x30\x46\x44\x33\x32\x0D");
			break;
		default:
			*len   = 0;
			break;
	}
}


/**********************************************************************************************************
* 函数名称： ASC2HEX
* 函数说明： ASCII转化为HEX
* 输入参数： ASCII字符
* 返回参数： 无
**********************************************************************************************************/
int asc2hex(char c)
{
	return (c >= '0' && c <= '9') ? c - '0' : (c|32) - 'a' + 10;
}


/**********************************************************************************************************
* 函数名称： int number(char *buf, int len)
* 函数说明： ASCII转化为数值
* 输入参数： ASCII字符缓存，数据字节数
* 返回参数： 数值
**********************************************************************************************************/
int number(char *buf, int len)
{
	unsigned int i, num=0;

	for(i=0; i<len; i++)
	{
		num<<=4;		
		num |= asc2hex(buf[i]);
	}	
	return num;
}


/**********************************************************************************************************
* 函数名称： int number(char *buf, int len)
* 函数说明： ASCII转化为数值
* 输入参数： ASCII字符缓存，数据字节数
* 返回参数： 数值
**********************************************************************************************************/
short Int16(char *buf)
{
	short i, num=0;

	for(i=0; i<4; i++)
	{
		num<<=4;		
		num |= asc2hex(buf[i]);
	}	
	return num;
}


/**********************************************************************************************************
* 函数名称： static unsigned short chksum(char *buf, int len)
* 函数说明： 电总协议校验数据包
* 输入参数： 数据包缓存区，数据包长度
* 返回参数： 有效数据长度
**********************************************************************************************************/
static int CheckDataPacket(char *buf, int len)
{
	unsigned int i, sum=0;

	if(buf[0]!=0x7E || buf[7]!=0x30 || buf[8]!=0x30 || buf[len-1]!=0x0D)  return 0;
	for(i=1; i<len-5; i++)
	{
		sum += buf[i];
	}
	sum = sum%65536;
	sum = ~sum + 1;
	sum &= 0x0000FFFF;
	if(number(buf+len-5,4)==sum)
	{
		sum = 0;
		for(i=10; i<13; i++)
		{
			sum += asc2hex(buf[i]);
		}
		sum = sum%16;
		sum = ~sum + 1;		
		if(asc2hex(buf[9])==(sum&0x0F))
		{
			return number(buf+10,3);
		}
	}
	return 0;
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	Data_Struct 	*d = (Data_Struct*)data;
	int	i;
	
	len = CheckDataPacket(buf,len);
	if(len)
	{
		switch(index)
		{
			case 0:
				d->indoorTemp.value.fnum 		= Int16(buf+13)*0.1;
				d->outdoorTemp.value.fnum 		= Int16(buf+17)*0.1;
				break;		
			case 1:
				d->setTempUpper.value.fnum 		= Int16(buf+21)*0.1;
				d->setTempLower.value.fnum 		= Int16(buf+25)*0.1;
				d->setCoolingTemp.value.fnum	= Int16(buf+37)*0.1;
				d->setHeatingTemp.value.fnum	= Int16(buf+41)*0.1;
				break;
			case 2:
				i = number(buf+15,2)&0x7F;
				d->runningState.value.str = i?"开机":"关机";
				Set_Var_Status(&d->runningState, i?Normal:Alarm, NULL);	
			
				d->autoMode.value.str = i&0x01?"启动":"停止";
				Set_Var_Status(&d->autoMode, i&0x01?ON:OFF, NULL);	
				d->energyMode.value.str = i&0x02?"启动":"停止";
				Set_Var_Status(&d->energyMode, i&0x02?ON:OFF, NULL);				
				d->freshAirMode.value.str = i&0x04?"启动":"停止";
				Set_Var_Status(&d->freshAirMode, i&0x04?ON:OFF, NULL);
				d->coldMode.value.str = i&0x08?"启动":"停止";
				Set_Var_Status(&d->coldMode, i&0x08?ON:OFF, NULL);	
				d->heatMode.value.str = i&0x10?"启动":"停止";
				Set_Var_Status(&d->heatMode, i&0x10?ON:OFF, NULL);				
				d->dehumiMode.value.str = i&0x20?"启动":"停止";
				Set_Var_Status(&d->dehumiMode, i&0x20?ON:OFF, NULL);
				d->standbyMode.value.str = i&0x40?"启动":"停止";
				Set_Var_Status(&d->standbyMode, i&0x40?ON:OFF, NULL);

				i = number(buf+17,2);
				d->indoorWindVolume.value.str 	= i&0x02?"高风":"低风";
				d->freshAirDoor.value.str 		= i&0x10?"开启":"关闭";
				Set_Var_Status(&d->freshAirDoor, i&0x10?ON:OFF, NULL);	
				d->outdoorFan.value.str 		= i&0x20?"开启":"关闭";								//室外风机：0：关,1：开
				Set_Var_Status(&d->outdoorFan, i&0x20?ON:OFF, NULL);	
				d->indoorFan.value.str 			= i&0x40?"开启":"关闭";								//室内风机：0：关,1：开	
				Set_Var_Status(&d->indoorFan, i&0x40?ON:OFF, NULL);					
				d->compressor.value.str 		= i&0x80?"开启":"关闭";								//压缩机状态,0：关/1：开
				Set_Var_Status(&d->compressor, i&0x80?ON:OFF, NULL);	
				
				i = number(buf+19,2);
				d->heater.value.str 			= i&0x01?"开启":"关闭";								//电加热状态,0：关/1：开
				Set_Var_Status(&d->heater, i&0x01?ON:OFF, NULL);					
				d->alarmOutput.value.str 		= i&0x08?"开启":"关闭";								//报警输出 0：关,1：开
				Set_Var_Status(&d->alarmOutput, i&0x08?ON:OFF, NULL);		
	
				i = number(buf+23,2);
				d->EEPROMFault.value.str 				= i&0x01?"错误":"正常";						//EEPROM参数故障,0:无/1:报警
				Set_Var_Status(&d->EEPROMFault, i&0x01?Alarm:Normal, NULL);					
				d->T1aFault.value.str 					= i&0x02?"故障":"正常";						//T1a温度传感器故障,0:无/1:报警
				Set_Var_Status(&d->T1aFault, i&0x02?Alarm:Normal, NULL);	
				d->T2Fault.value.str 					= i&0x04?"故障":"正常";						//T2温度传感器故障,0:无/1:报警
				Set_Var_Status(&d->T2Fault, i&0x04?Alarm:Normal, NULL);				
				d->T3Fault.value.str 					= i&0x08?"故障":"正常";						//T3温度传感器故障,0:无/1:报警	
				Set_Var_Status(&d->T3Fault, i&0x08?Alarm:Normal, NULL);					
				d->T4Fault.value.str 					= i&0x10?"故障":"正常";						//T4温度传感器故障,0:无/1:报警	
				Set_Var_Status(&d->T4Fault, i&0x10?Alarm:Normal, NULL);					
				d->airFlowAlarm.value.str 				= i&0x20?"故障":"正常";						//空气流量报警,0:无/1:报警
				Set_Var_Status(&d->airFlowAlarm, i&0x20?Alarm:Normal, NULL);					
				d->lostPhase.value.str 					= i&0x40?"故障":"正常";						//电源缺相,0:无/1:报警
				Set_Var_Status(&d->lostPhase, i&0x40?Alarm:Normal, NULL);					
				d->exhaustTempSensor.value.str 	= i&0x80?"故障":"正常";								//排气温度传感器故障,0:无/1:报警
				Set_Var_Status(&d->exhaustTempSensor, i&0x80?Alarm:Normal, NULL);					

				i = number(buf+25,2);
				d->humiSensor.value.str 			= i&0x01?"故障":"正常";							//湿度传感器故障,0:无/1:报警	
				Set_Var_Status(&d->humiSensor, i&0x01?Alarm:Normal, NULL);					
				d->T1bFault.value.str 					= i&0x08?"故障":"正常";						//T1b温度传感器故障,0:无/1:报警	
				Set_Var_Status(&d->T1bFault, i&0x08?Alarm:Normal, NULL);					
				d->voltageFault.value.str 				= i&0x10?"故障":"正常";						//电压故障,0:无/1:报警	
				Set_Var_Status(&d->voltageFault, i&0x10?Alarm:Normal, NULL);					
				d->photoelectricSwitch.value.str 		= i&0x20?"故障":"正常";						//光电开关,0:无/1:报警	
				Set_Var_Status(&d->photoelectricSwitch, i&0x20?Alarm:Normal, NULL);					
				d->leakingAlarm.value.str 				= i&0x40?"故障":"正常";						//漏水报警,0:无/1:报警	
				Set_Var_Status(&d->leakingAlarm, i&0x40?Alarm:Normal, NULL);					
				d->fireAlarm.value.str 					= i&0x80?"故障":"正常";						//烟火报警,0:无/1:报警
				Set_Var_Status(&d->fireAlarm, i&0x80?Alarm:Normal, NULL);					

				i = number(buf+27,2);
				d->indoorHighTemp.value.str 			= i&0x02?"故障":"正常";						//室内高温报警,0:无/1:报警	
				Set_Var_Status(&d->indoorHighTemp, i&0x02?Alarm:Normal, NULL);					
				d->indoorLowTemp.value.str 				= i&0x04?"故障":"正常";						//室内低温报警,0:无/1:报警	
				Set_Var_Status(&d->indoorLowTemp, i&0x04?Alarm:Normal, NULL);					
				d->indoorEvaporatorProtection.value.str	= i&0x10?"故障":"正常";						//室内蒸发器高温或低温保护,0:无/1:报警
				Set_Var_Status(&d->indoorEvaporatorProtection, i&0x10?Alarm:Normal, NULL);					
				d->outdoorCondenserProtection.value.str	= i&0x20?"故障":"正常";						//室外冷凝器高温保护,0:无/1:报警
				Set_Var_Status(&d->outdoorCondenserProtection, i&0x20?Alarm:Normal, NULL);					
				d->exhausthighTempProtection.value.str	= i&0x80?"故障":"正常";						//排气高温保护,0:无/1:报警
				Set_Var_Status(&d->exhausthighTempProtection, i&0x80?Alarm:Normal, NULL);					
				
				i = number(buf+29,2);								
				d->compressorLowPressure.value.str		= i&0x04?"故障":"正常";						//压缩机低压故障,0:无/1:报警
				Set_Var_Status(&d->compressorLowPressure, i&0x04?Alarm:Normal, NULL);					
				d->compressorHighPressure.value.str		= i&0x08?"故障":"正常";						//压缩机高压故障,0:无/1:报警	
				Set_Var_Status(&d->compressorHighPressure, i&0x08?Alarm:Normal, NULL);					
				d->compressorOverload.value.str			= i&0x10?"故障":"正常";						//压缩机电流过载故障,0:无/1:报警
				Set_Var_Status(&d->compressorOverload, i&0x10?Alarm:Normal, NULL);					
				d->heaterOverload.value.str				= i&0x20?"故障":"正常";						//电加热过载故障,0:无/1:报警
				Set_Var_Status(&d->heaterOverload, i&0x20?Alarm:Normal, NULL);					

				i = number(buf+31,2);			
				d->filterBlock.value.str				= i&0x40?"故障":"正常";						//新风过滤网脏堵,0:无/1:报警
				Set_Var_Status(&d->filterBlock, i&0x40?Alarm:Normal, NULL);					
				break;				
			case 3:
				d->indoorFanRunTime.value.inum			= number(buf+13,8);							//内风机运行时间
				d->compressorRunTime.value.inum			= number(buf+21,8);							//压缩机运行时间
				d->outdoorFanRunTime.value.inum			= number(buf+29,8);							//外风机运行时间
				d->freshAirRunTime.value.inum			= number(buf+37,8);							//换新风运行时间
				d->heaterRunTime.value.inum				= number(buf+45,8);							//加热器运行时间
				break;
			case 4:
				d->powerConsumption.value.inum			= number(buf+27,8);							//总耗电量
				break;
			default:
				break;
		
		}
		return 0;
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void jmkt_SAF13WTR00_Registration(void)
* 函数说明： 精密空调驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void jmkt_SAF13WTR00_Registration(void)
{
	Device_Registration(
		"jmkt",													//设备类型
		"精密空调",												//设备名称（导航栏默认显示名称）
		"SAF13WTR00",											//设备型号
		"美的精密空调监测",										//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun												//数据解析函数
	);
}

